package com.leetcode.partition11;

import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2021/9/21 9:41
 */
public class LC1014最佳观光组合 {

    public static int maxScoreSightseeingPair(int[] values) {
//        return dynamicProgramming(values);
        int answer = 0, max = values[0] + 0;
        for (int j = 1; j < values.length; j++) {
            answer = Math.max(answer, max + values[j] - j);
            max = Math.max(max, values[j] + j);
        }
        return answer;
    }

    public static void main(String[] args) {
        int[] values = {8, 1, 5, 2, 6};
        System.out.println(maxScoreSightseeingPair(values));
    }

    private static int dynamicProgramming(int[] values) {
        int[][] dp = new int[values.length + 1][values.length + 1];
        for (int i = 1; i < dp.length; i++) {
            for (int j = i; j < dp[i].length; j++) {
                if (i == j) {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                    continue;
                }
                dp[i][j] = Math.max(Math.max(dp[i - 1][j], dp[i][j - 1]), values[i - 1] + values[j - 1] + i - j);
            }
        }
        Arrays.stream(dp).forEach(val -> System.out.println(Arrays.toString(val)));
        return dp[values.length][values.length];
    }
}
